<?php

require('BinaryBeast.php');
require_once('Model/PlayerModel.php');
require_once('Model/TeamModel.php');

class BinaryBeastHelper {

private $bb;
private $db;

    function __construct()
    {
        $this->bb = new BinaryBeast('3e1d237b266f29ad9d5ac1867052dba9.51478ee32ffa49.02266793');
        $this->db = mysqli_connect("localhost", "root", "Pewpew", "Pewpew");
    }

    public function CreateTeam($tournamentId, $teamName, $playerNames )
    {
        echo "sup";
        $team = new TeamModel($teamName);
        $playerArray = array();

        foreach($playerNames as &$playerName)
        {
            //Create PlayerModel object
            $tempPlayer = new PlayerModel($playerName, $teamName);
            //Insert into PlayerModel object array
            $playerArray[] = $tempPlayer;
        }

        $this->bb->disable_ssl_verification();

        $result = $this->bb->team_insert($tournamentId, $teamName, $playerNames);

        //OH NOES!
        if($result->result != 200)
        {
            var_dump($result);
            die('Error inserting team ' . $teamName);
        }

        //Let's store an array of inserted teams, so we can match up
        //team id's with the actual names later on
        //Success! ok so
        $team_ids[ $result->tourney_team_id ] = $teamName;

        echo $teamName . ' added, his tourney_team_id is: ' . $result->tourney_team_id . ' (' . $result->api_total_time . ' execution) <br />';
    }
}